#ifndef _BUTTONMANAGER_H_
#define _BUTTONMANAGER_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "Button.h"

typedef void (*ButtonEventCb)(uint8_t);

typedef struct _ButtonNode
{
    Button button;

    uint8_t id;
    uint8_t enable : 1;
    uint8_t event : 3;
    uint8_t pressed : 1;
    ButtonEventCb eventCb; // 按钮事件回调函数，由用户定义

    struct _ButtonNode *next;
}ButtonNode;

enum
{
    ButtonGroudActivePressed = 0,
    ButtonGroupActiveRelease,
};

typedef void(*ButtonGroupEventCb)(void);

typedef struct _ButtonGroupNode
{
    struct
    {
        ButtonNode *button;
        uint8_t active : 1;
    }items[4];

    uint16_t longPressTrigTime;
    uint16_t pressTick;
    uint8_t id : 7;
    uint8_t enable : 1;
    ButtonGroupEventCb eventCb;

    struct _ButtonGroupNode *next;
}ButtonGroupNode;

void ButtonManagerAddButton(ButtonNode *buttonNode, ButtonEventCb buttonEventCb);
void ButtonManagerAddButtonGroup(ButtonGroupNode *buttonGroupNode, uint16_t longPressTrigTime, ButtonGroupEventCb buttonGroupEventCb);
void ButtonManagerGroupSetItem(ButtonGroupNode *buttonGroupNode, uint8_t index, uint8_t id, uint8_t active);

void ButtonManagerDisableButton(uint8_t buttonId);
void ButtonManagerEnableButton(uint8_t buttonId);

void ButtonManagerDisableGroup(uint8_t groupId);
void ButtonManagerEnableGroup(uint8_t groupId);

void ButtonManagerHandler(void);


#ifdef __cplusplus
}
#endif

#endif
